import os

def bs(path):
    n = 1
    for f in os.listdir(path):
        newname = f.split("_")[-1]
        
        os.rename(os.path.join(path,f),os.path.join(path,newname))



 
def batch_rename_files(directory, old_string):
    for filename in os.listdir(directory):
        if old_string in filename:
            new_filename = filename.replace(old_string, "")
            os.rename(os.path.join(directory, filename), os.path.join(directory, new_filename))


path1 = r"E:\biaozhipai\JPEGImages"
path2 = r"D:\zhenghe_biaozhipai\crop_out\shaixuan\40140003\100"
#bs(path)
old_string = "2023-09-08 "
# old_string = "2023-10-10 "
batch_rename_files(path2,old_string)